﻿using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace Medicalsystem.MCP.FormDesigner.Ctl
{
    /// <summary>
    /// 关闭控件-呈现为一个 X
    /// </summary>
    public class ctl_HeaderClose : System.Windows.Forms.Control
    {
        protected override void OnPaint(PaintEventArgs pe)
        {
            // TODO: 在此处添加自定义绘制代码

            try
            {
                //某些操作系统不支持系统定制样式
                if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.ExplorerBar.HeaderClose.Normal))
                {
                    VisualStyleRenderer renderer2 =
                         new VisualStyleRenderer(VisualStyleElement.ExplorerBar.HeaderClose.Normal);
                    Rectangle rectangle2 = new Rectangle(0, 0, Math.Abs(this.Width), Math.Abs(this.Height));
                    renderer2.DrawBackground(pe.Graphics, rectangle2);
                }
            }
            catch
            {
                //不支持的系统采用手绘
                Pen pen = new Pen(Color.Black, 2);

                pe.Graphics.DrawLine(pen, new Point(5, 5), new Point(Math.Abs(this.Width - 7), Math.Abs(this.Height - 5)));
                pe.Graphics.DrawLine(pen, new Point(Math.Abs(this.Width - 7), 5), new Point(5, Math.Abs(this.Height - 5)));

                // 调用基类 OnPaint
                base.OnPaint(pe);
            }
        }
    }
}